package com.codefactory;

import com.alibaba.fastjson.JSONObject;
import com.codefactory.generator.model.ModelVO;
import com.codefactory.generator.service.CodeGenerator;
import com.codefactory.generator.service.ModelService;
import org.apache.commons.io.FileUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.io.File;
import java.util.List;

@SpringBootTest
@RunWith(SpringRunner.class)
public class TestGenerator {
    @Autowired
    private CodeGenerator codeGenerator;
    @Autowired
    private ModelService modelService;
    private static final String USER_DIR = System.getProperty("user.dir");

    @Test
    public void testGen() throws Exception {
        File tableNameFile = FileUtils.getFile(USER_DIR, "FTXT", "Service.ftl");

        JSONObject object = new JSONObject();
        object.put("basePackage", "org");
        object.put("date", "2019");
        object.put("author", "yy");
        object.put("tableComment", "测试");
        object.put("className", "Windows");

        String code = codeGenerator.generateCodeToString(tableNameFile, object);
        System.out.println(code);

        List<ModelVO> voList = modelService.generate("sys_config", "sys_dict", "sys_login_log");
        System.out.println(voList.size());
    }
}
